home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Magazine Collection 2001
/
Delphi Magazine Collection 20001 (2001).iso
/
DISKS
/
Issue38
/
Alfresco
/
Project1.dpr
< prev
Wrap
Text File
|
1998-09-01
|
5KB
|
184 lines
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils,
Graphs in 'Graphs.pas';
procedure PreProcess(aSender : TObject; aNodeInx : integer);
begin
writeln('PreProcessing node ', aNodeInx);
end;
procedure PostProcess(aSender : TObject; aNodeInx : integer);
begin
writeln('PostProcessing node ', aNodeInx);
end;
const
EdgeExists = pointer(1);
var
FMGraph : TaaFullMatrixGraph;
TMGraph : TaaTriMatrixGraph;
LLGraph : TaaLinkListGraph;
Iter : TaaDepthFirstIterator;
i, j : integer;
Edge : pointer;
ToInx : integer;
begin
try
FMGraph := TaaFullMatrixGraph.Create(10, false);
try
with FMGraph do begin
Edges[0, 6] := EdgeExists;
Edges[0, 9] := EdgeExists;
Edges[9, 8] := EdgeExists;
Edges[7, 8] := EdgeExists;
Edges[5, 6] := EdgeExists;
Edges[5, 4] := EdgeExists;
Edges[5, 3] := EdgeExists;
Edges[5, 8] := EdgeExists;
Edges[5, 7] := EdgeExists;
Edges[2, 1] := EdgeExists;
Edges[2, 3] := EdgeExists;
Edges[2, 4] := EdgeExists;
Edges[1, 3] := EdgeExists;
writeln('---full matrix graph');
writeln(' 0 1 2 3 4 5 6 7 8 9');
for i := 0 to 9 do begin
write(i:2);
for j := 0 to 9 do begin
if Edges[i, j] <> nil then
write(' 1')
else
write(' .');
end;
write(' ');
j := 0;
while GetNodeEdge(i, j, Edge, ToInx) do begin
write(ToInx:2);
inc(j);
end;
writeln;
end;
end;
Iter := TaaDepthFirstIterator.Create(FMGraph);
try
Iter.OnPreProcess := PreProcess;
Iter.OnPostProcess := PostProcess;
Iter.Execute(0);
finally
Iter.Free;
end;
finally
FMGraph.Free;
end;
readln;
//
TMGraph := TaaTriMatrixGraph.Create(10);
try
with TMGraph do begin
Edges[0, 6] := EdgeExists;
Edges[0, 9] := EdgeExists;
Edges[9, 8] := EdgeExists;
Edges[7, 8] := EdgeExists;
Edges[5, 6] := EdgeExists;
Edges[5, 4] := EdgeExists;
Edges[5, 3] := EdgeExists;
Edges[5, 8] := EdgeExists;
Edges[5, 7] := EdgeExists;
Edges[2, 1] := EdgeExists;
Edges[2, 3] := EdgeExists;
Edges[2, 4] := EdgeExists;
Edges[1, 3] := EdgeExists;
writeln('---triangular matrix graph');
writeln(' 0 1 2 3 4 5 6 7 8 9');
for i := 0 to 9 do begin
write(i:2);
for j := 0 to 9 do begin
if Edges[i, j] <> nil then
write(' 1')
else
write(' .');
end;
write(' ');
j := 0;
while GetNodeEdge(i, j, Edge, ToInx) do begin
write(ToInx:2);
inc(j);
end;
writeln;
end;
end;
Iter := TaaDepthFirstIterator.Create(TMGraph);
try
Iter.OnPreProcess := PreProcess;
Iter.OnPostProcess := PostProcess;
Iter.Execute(0);
finally
Iter.Free;
end;
finally
TMGraph.Free;
end;
readln;
//
LLGraph := TaaLinkListGraph.Create(10, false);
try
with LLGraph do begin
Edges[0, 6] := EdgeExists;
Edges[0, 9] := EdgeExists;
Edges[9, 8] := EdgeExists;
Edges[7, 8] := EdgeExists;
Edges[5, 6] := EdgeExists;
Edges[5, 4] := EdgeExists;
Edges[5, 3] := EdgeExists;
Edges[5, 8] := EdgeExists;
Edges[5, 7] := EdgeExists;
Edges[2, 1] := EdgeExists;
Edges[2, 3] := EdgeExists;
Edges[2, 4] := EdgeExists;
Edges[1, 3] := EdgeExists;
writeln('---linked list graph');
writeln(' 0 1 2 3 4 5 6 7 8 9');
for i := 0 to 9 do begin
write(i:2);
for j := 0 to 9 do begin
if Edges[i, j] <> nil then
write(' 1')
else
write(' .');
end;
write(' ');
j := 0;
while GetNodeEdge(i, j, Edge, ToInx) do begin
write(ToInx:2);
inc(j);
end;
writeln;
end;
end;
Iter := TaaDepthFirstIterator.Create(LLGraph);
try
Iter.OnPreProcess := PreProcess;
Iter.OnPostProcess := PostProcess;
Iter.Execute(0);
finally
Iter.Free;
end;
finally
LLGraph.Free;
end;
except
on E:Exception do
writeln(E.Message);
end;
readln;
end.